package com.situ.root.user.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.situ.root.user.mapper.UserMapper;
import com.situ.root.user.model.UserModel;
import com.situ.root.user.service.IUSerService;
//@Transactional(propagation = Propagation.REQUIRES_NEW)
@Transactional
@Service
public class UserServiceImpl implements IUSerService{

	@Autowired
	private UserMapper userMapper;
	
	@Override
	public int insert(UserModel model) {
		
		return selectId(model.getCode())==null? userMapper.insert(model):0;
	}
	
	@Override
	public List<UserModel> selectList(UserModel model){
		return userMapper.selectAll(model);
	}
	
	@Override
	public int delete(Object id) {
		return userMapper.delete(id);
	}
	
	@Override
	public int update(UserModel model) {
		return userMapper.update(model);
	}
	
	@Override
	public int selectCount(UserModel model) {
		return userMapper.selectCount(model);
	}
	
	@Override
	public UserModel selectId(String id) {
		return userMapper.selectId(id);
	}
	
	@Override
	public int login(UserModel model) {
		UserModel m1 = new UserModel(model.getCode());
		List<UserModel> list = userMapper.selectAll(m1);
		if(list==null||list.isEmpty()) {return 0;}
		UserModel m2 = list.get(0);
		if(m2.getPass().equals(model.getPass()))return 1;
		else return 2;
	}
//	int updateActive(UserModel t);
}
